package com.all.play.myadaptertoadapter.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.all.play.myadaptertoadapter.R;
import com.all.play.myadaptertoadapter.adapter.MyFirstAdapter;
import com.all.play.myadaptertoadapter.bean.MyBean;
import com.all.play.myadaptertoadapter.fakefata.ResaultData;
import com.google.gson.Gson;

/**
 * Created by 聪明一只哈 on 2018/5/18.
 * Time: 2018/5/18  8:24
 */

public class FirstActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private MyFirstAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);

        initView();

        initData();
    }

    private void initData() {

        String data = ResaultData.data;
        Gson gson = new Gson();
        MyBean myBean = gson.fromJson(data, MyBean.class);
        if(myBean!=null){
            MyBean.ResultBean result = myBean.getResult();
            adapter = new MyFirstAdapter(this, result);

            recyclerView.setLayoutManager(new LinearLayoutManager(this));

            recyclerView.setAdapter(adapter);

            adapter.setOneTransListener(new MyFirstAdapter.OneTransListener() {
                @Override
                public void show(String string) {
                    Toast.makeText(FirstActivity.this, ""+ string, Toast.LENGTH_SHORT).show();
                }
            });
        }


    }

    private void initView() {
        recyclerView = (RecyclerView) findViewById(R.id.rv_first);

        String data = ResaultData.data;


    }
}
